package com.xiangyang.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiangyang.entity.User;
import com.xiangyang.entity.dto.Result;
import com.xiangyang.entity.vo.UserInfoPage;
import com.xiangyang.service.IUserInfoService;
import com.xiangyang.service.impl.UserInfoServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserInfoController {

    private static final Logger logger = LoggerFactory.getLogger(UserInfoController.class);

    @Autowired
    private IUserInfoService userInfoService;
    @Autowired
    private UserInfoServiceImpl userInfoServiceImpl;

    // 获取用户信息
    @GetMapping("/getUserInfo")
    public Result getUserInfo(User user) {
        return userInfoService.getUserInfo(user);
    }


    // 删除用户信息
    @DeleteMapping("/deleteInfo")
    @PreAuthorize("hasAnyAuthority('sys:employee')")
    public Result deleteUserInfo( Long userId) {
        return userInfoServiceImpl.deleteUserInfo(userId);
    }

    // 更新用户信息
    @PutMapping("/updateUserInfo")
    @PreAuthorize("hasAnyAuthority('sys:employee')")
    public Result updateUserInfo(@RequestBody User user) {
        return userInfoServiceImpl.updateUserInfo(user);
    }
    @PostMapping("/selectUserInfo")
    public Result selectUserInfo(@RequestBody UserInfoPage userInfoPage){
        return userInfoServiceImpl.selectUserInfo(userInfoPage);
    }

}